<template>
  <div class="navItem" v-loading="loading">
    <el-row :gutter="20">
      <el-col
        class="item"
        v-for="item in itemList"
        :key="item.createTime"
        :span="5"
      >
        <el-card shadow="never">
          <el-image
            class="img"
            style="width: 100%; height: 125.88px; border-radius: 5px;"
            :src="item.moreBackup.videos[0].cover"
            @click="toVideo"
          />
          <img src="https://rs.dance365.com/img/release_play@3x.fb313c4d.png" />
          <div class="item-btm">
            <div class="item-btm-top">
              <div class="item-btm-top-w">
                <div class="item-btm-top-w-l">
                  <span></span>
                  <!-- 歌名字 -->
                  <a href="javascript:;">{{ item.title }}</a>
                </div>
              </div>
              <div class="item-btm-top-num">
                <span>{{ item.statisticsBackup.viewCount }}人预览</span>
              </div>
              <div class="item-btm-top-zan">
                <span class="item-btm-top-zan-one">
                  <el-icon><Pointer /></el-icon>
                  <!-- 喜欢 -->
                  <span>{{ item.statisticsBackup.praiseCount }}</span>
                </span>
                <span class="item-btm-top-zan-one">
                  <el-icon><ChatDotRound /></el-icon>
                  <!-- 点赞 -->
                  <span>{{
                    item.statisticsBackup.requireVideoCourseCount
                  }}</span>
                </span>
                <span class="item-btm-top-zan-one">
                  <el-icon><Star /></el-icon>
                  <!-- 收藏 -->
                  <span>{{ item.statisticsBackup.favoriteCount }}</span>
                </span>
              </div>
            </div>
            <div class="item-btm-btm">
              <div class="item-btm-btm-user">
                <!-- 作者头像 -->
                <el-image
                  class="item-btm-btm-user-img"
                  :src="item.creatorBackup.avatar"
                ></el-image>
                <!-- 作者名字 -->
                <span class="item-btm-btm-user-name">{{
                  item.creatorBackup.name
                }}</span>
              </div>
              <!-- 日期 -->
              <span class="time">11-07</span>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 回到顶部按钮 -->
    <div class="backTop" ref="back">
      <el-backtop>
        <el-icon style="
            height: 100%;
            width: 100%;
            background-color: var(--el-bg-color-overlay);
            text-align: center;
            line-height: 40px;
          ">
          <ArrowUp />
        </el-icon>
      </el-backtop>
    </div>
    <!-- 按钮加载 -->
    <div><button class="btn" @click="clickPush">加载更多</button></div>
  </div>
</template>

<script setup lang="ts">
// @ts-ignore
import { Pointer, ChatDotRound, Star,ArrowUp } from "@element-plus/icons-vue";
import homeApi, { type ContentModel } from "@/api/home";
import { onMounted, ref } from "vue";
import router from "@/router";
// 加载
const loading = ref(false);
// 首页推荐的请求
const itemList = ref<ContentModel[]>([]);
const getRecommend = async () => {
  loading.value = true;
  try {
    let result = await homeApi.reqRecommend();
    // @ts-ignore
    for (let i = 0; i < result.content.length; i++) {
      // @ts-ignore
      itemList.value.push(result.content[i])
    }
    loading.value = false;
  } catch (error) {
    console.error(error);
  }
};
// 跳转
const toVideo = ()=>{
  router.push({path:'/detail/video'})
}
// 给原先的数据添加
const clickPush = ()=>{
  getRecommend()
}
onMounted(() => {
  getRecommend()
});
</script>

<style scoped lang="less">
.navItem {
  // display: flex;
  // justify-content: center;
  // align-items: flex-start;
  flex-wrap: wrap;
  margin: 0 auto;
  width: 1200px;
  .item {
    margin: 0;
    padding: 0;
    position: relative;
    margin-bottom: 10px;
    img {
      position: absolute;
      bottom: 162px;
      left: 10px;
      display: inline-block;
      width: 30px;
      height: 30px;
      // 蒙版
      &:hover{
        background: #ccc;
        opacity: 0.5;
      }
    }
    .item-btm {
      width: 100%;
      color: #b1b5c1;
      height: 155px;
      .item-btm-top {
        padding-right: 10px;
        padding-left: 10px;
        padding-bottom: 13px;
        border-bottom: 1px solid #ebeced;
        height: 104px;
        .item-btm-top-w {
          font-size: 14px;
          color: #111;
          padding-top: 10px;
          padding-bottom: 0;
          line-height: 18px;
          height: 45px;
          width: 100%;
          .item-btm-top-w-l {
            span {
              background: url(https://rs.dance365.com/title_original.svg)
                no-repeat;
              background-size: cover;
              box-sizing: border-box;
              margin-right: 6px;
              display: inline-block;
              width: 24px;
              height: 16px;
              vertical-align: bottom;
            }
            a {
              text-decoration: none;
              color: #111;
            }
          }
        }
        .item-btm-top-num {
          display: flex;
          -webkit-box-pack: justify;
          justify-content: space-between;
          -webkit-box-align: center;
          align-items: center;
          height: 32px;
          line-height: 32px;
          span {
            font-size: 12px;
            line-height: 32px;
          }
        }
        .item-btm-top-zan {
          display: flex;
          -webkit-box-align: center;
          align-items: center;
          font-size: 12px;
          height: 28px;
          line-height: 12px;
          .item-btm-top-zan-one {
            color: #b1b5c1;
            font-size: 16px;
            line-height: 16px;
            span {
              box-sizing: border-box;
              max-width: 36px;
              margin-right: 18px;
            }
          }
        }
      }
      .item-btm-btm {
        box-sizing: border-box;
        display: flex;
        -webkit-box-align: center;
        align-items: center;
        -webkit-box-pack: justify;
        justify-content: space-between;
        height: 38px;
        padding-left: 16px;
        position: relative;
        font-size: 12px;
        .item-btm-btm-user {
          max-width: 128px;
          display: flex;
          -webkit-box-align: center;
          .item-btm-btm-user-img {
            width: 24px;
            height: 24px;
            border-radius: 50%;
          }
          .item-btm-btm-user-name {
            line-height: 24px;
            max-width: 88px;
            color: #111;
            cursor: pointer;
            margin-left: 8px;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
          }
        }
        .time {
          padding-right: 8px;
        }
      }
    }
  }
  /deep/.el-backtop {
    position: fixed;
    bottom: 320px !important;
    right: 110px !important;
    box-shadow: none !important;
  }
  //
  .btn {
    display: block;
    width: 140px;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    color: #82858e;
    border: 1px solid #eaecf0;
    border-radius: 4px;
    background: #fff;
    text-align: center;
    margin: 20px auto 0;
    cursor: pointer;
    margin-bottom: 20px;
  }
}
</style>
